package main

import "math"

func reverse(x int) int {
	x64 := int64(x)
	negative := false
	if x64 < 0 {
		negative = true
		x64 = -x64
	}
	result := int64(0)
	for x64 > 0 {
		bit := x64 % 10
		result = result*10 + bit
		x64 /= 10
	}
	if negative {
		result = -result
	}
	if result > math.MaxInt32 || result < math.MinInt32 {
		return 0
	}
	return int(result)
}

func main() {
	println(reverse(-2147483647))
}
